package asteroids.model.expressions;

import exceptions.IllegalOperandException;

/**
 * A subclass of expression (E) that represents the or (||) comparison of two booleans
 * 
 * @version 1.0
 * 
 * @author	Thijs Peirelinck & Wouter Parys
 *
 */
public class Or extends BooleanComparison {

	public Or(E e1, E e2) {
		super(e1,e2);
	}
	
	@Override
	public Boolean getValue() throws IllegalOperandException {
		if(!this.isValidExpression()) { throw new IllegalOperandException(); }
		boolean left = ((Boolean)getLeftOperand().getValue());
		boolean right = ((Boolean)getRightOperand().getValue());
		return left || right;
	}
	
	@Override
	public String toString() {
		return getLeftOperand().toString() + " || " + getRightOperand().toString();
	}
	
	@Override
	public E createCopy() {
		return new Or(getLeftOperand().createCopy(), getRightOperand().createCopy());
	}
}
